//
//  ZXViewController.m
//  emark
//
//  Created by zhoucan on 2018/3/27.
//  Copyright © 2018年 neebel. All rights reserved.
//

#import "ZXViewController.h"
#import <UIImageView+WebCache.h>
#import "WeeViewController.h"
#import <AVOSCloud/AVOSCloud.h>
@interface ZXViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@property(nonatomic,strong)NSMutableArray<AVObject*> *list;

@end

@implementation ZXViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.list = [NSMutableArray array];
    self.navigationItem.title = @"理财知识";
    self.tableview.tableFooterView = [UIView new];
    // Do any additional setup after loading the view.
    
    [self loadData];
    
}


- (void)loadData{
    
    AVQuery *query = [AVQuery queryWithClassName:@"new"];
     NSArray<AVObject*> *lista =  query.findObjects;
    
    
    [self.list addObjectsFromArray:lista];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"acell" forIndexPath:indexPath];
    
    UIImageView * im = (UIImageView * )[cell.contentView viewWithTag:10000];
    UILabel * la = (UILabel *)[cell.contentView viewWithTag:20000];
    UILabel * xx = (UILabel *)[cell.contentView viewWithTag:30000];
    
    AVObject * obj = self.list[indexPath.row];
    NSString * imageUrl = obj[@"newsurl"];
    NSString * title = obj[@"newstitle"];
    NSString * detail = obj[@"newsdetail"];
    
    
        [im sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
        la.text = title;
        xx.text = detail;
    


    
    
    
    
    
  
    
    
    return cell;
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    WeeViewController *vc = [[WeeViewController alloc] initWithNibName:@"WeeViewController" bundle:nil];
    vc.isHidden = NO;
    AVObject * obj = self.list[indexPath.row];
    NSString * url = obj[@"detailurl"];
    
   vc.url = url;
    
    vc.hidesBottomBarWhenPushed = YES;
   
    [self.navigationController pushViewController:vc animated:YES];
    
}



@end
